﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.IO;
using System.Windows;

namespace WpfPdfReader
{
    public class BrushHelper
    {
        public static ImageBrush GetBrush(Uri uri)
        {
            System.Windows.Resources.StreamResourceInfo info = Application.GetResourceStream(uri);
            return GetBrush(info.Stream);
            //ImageBrush imageBrush = new ImageBrush();
            //BitmapImage bitmapimage = new BitmapImage(url);
            //imageBrush.ImageSource = bitmapimage;
            //return imageBrush;
        }

        public static ImageBrush GetBrush(Stream streamSource)
        {
            ImageBrush imageBrush = new ImageBrush();
            BitmapImage bitmapimage = new BitmapImage();
            bitmapimage.BeginInit();
            bitmapimage.StreamSource = streamSource;
            bitmapimage.EndInit();
            imageBrush.ImageSource = bitmapimage;
            return imageBrush;
        }

        public static BitmapImage GetBitmapImage(Uri uri)
        {
            System.Windows.Resources.StreamResourceInfo info = Application.GetResourceStream(uri);
            BitmapImage bitmapimage = new BitmapImage();
            bitmapimage.BeginInit();
            bitmapimage.StreamSource = info.Stream;
            bitmapimage.EndInit();
            return bitmapimage;
        }

        public static BitmapImage GetBitmapImageFromStream(Stream bitmapStream)
        {
            BitmapImage bitmapimage = new BitmapImage();
            bitmapimage.BeginInit();
            bitmapimage.StreamSource = bitmapStream;
            bitmapimage.EndInit();
            return bitmapimage;
        }
    }
}
